package com.pany.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.apache.commons.collections.CollectionUtils;

import play.db.jpa.JPABase;

import com.pany.domain.models.TranType;

public class TranTypeService
{
    public static Map<String, TranType> getTranTypeMapByIdList(
            List<String> idList)
    {

        StringBuilder hql = new StringBuilder(
                "from TranType where tranTypeId in(");
        for (int i = 0; i < idList.size(); i++)
        {
            hql.append("?").append(",");
        }
        hql.deleteCharAt(hql.length() - 1);
        hql.append(")");
        Query q = JPABase.em().createQuery(hql.toString());
        for (int i = 0; i < idList.size(); i++)
        {
            q.setParameter(i + 1, idList.get(i));
        }
        List<TranType> list = q.getResultList();
        Map<String, TranType> map = new HashMap<String, TranType>();
        if (CollectionUtils.isNotEmpty(list))
        {
            for (TranType tranType : list)
            {
                map.put(tranType.getTranTypeId(), tranType);
            }
        }
        return map;
    }
}
